package presentation;
//package solitaire.presentation ;

//-------------------------------------------------------------------------------------

//import solitaire.controle.* ;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import controle.CCarte;
import controle.ICCarte;
import controle.ICTas;

//-------------------------------------------------------------------------------------

public class PCarte extends JPanel implements IPCarte, Transferable{

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected CCarte controle ;
    protected JLabel face ;
    protected JLabel dos ;
    protected ImageIcon icone ;
    private ICCarte controleur;

    public PCarte(){
    	initDimensions();
        setLayout (null) ;
        setBackground (Color.yellow) ;
        setOpaque (false) ;
        setSize (largeur, hauteur) ;
        setPreferredSize (getSize ()) ;
    }
    
    public PCarte(int couleur){
    	String chaine="";
    	initDimensions();
        setLayout (null) ;
        setBackground (Color.yellow) ;
        switch(couleur){
        case 1 : chaine="D"; break;
        case 2 : chaine="S"; break;
        case 3 : chaine="H"; break;
        case 4 : chaine="C"; break;
        }
        icone = new ImageIcon (ClassLoader.getSystemResource("cartesCSHD/" + chaine + ".gif")) ;
        face = new JLabel (icone) ;
        add (face) ;
        face.setLocation (0, 0) ;
        face.setSize (largeur, hauteur) ;
        setOpaque (false) ;
        setSize (face.getSize ()) ;
        setPreferredSize (getSize ()) ;
        setFaceVisible(true);
    }

   public PCarte (final String chaine, final CCarte controle) {
    //public PCarte (final String chaine) {
	    setControleur(controle);
    	initDimensions();
        setLayout (null) ;
        setBackground (Color.yellow) ;
        icone = new ImageIcon (ClassLoader.getSystemResource("cartesCSHD/" + chaine + ".gif")) ;
        face = new JLabel (icone) ;
        add (face) ;
        face.setLocation (0, 0) ;
        face.setSize (largeur, hauteur) ;
        ImageIcon iconeDos = new ImageIcon (ClassLoader.getSystemResource("cartesCSHD/bluegreencrisscross.jpg")) ;
        dos = new JLabel (iconeDos) ;
        dos.setSize (face.getSize ()) ;
        add (dos) ;
        dos.setLocation (0, 0) ;
        setOpaque (false) ;
        setSize (face.getSize ()) ;
        setPreferredSize (getSize ()) ;
        setFaceVisible(controle.isFaceVisible());
    }

    public void setFaceVisible (boolean faceVisible) {
        face.setVisible (faceVisible) ;
    }

   //public final CCarte getControle () {
       //return (controle) ;
   //}

    public void paint (Graphics g) {
        super.paint (g) ;
        g.drawRect (0, 0, getWidth () - 1, getHeight () - 1) ;
    }

    public ImageIcon getIcone () {
        return (icone) ;
    }

    public static int largeur ;
    public static int hauteur ;

    public static void initDimensions () {
        ImageIcon icone = new ImageIcon (ClassLoader.getSystemResource("cartesCSHD/1C.gif")) ;
        largeur = icone.getIconWidth () ;
        hauteur = icone.getIconHeight () ;
    }

  /* public static void main (String args []) {
    /*  initDimensions () ;
      JFrame f = new JFrame ("Test PCarte") ;
      f.getContentPane ().add (new PCarte ("1C")) ;
      f.addWindowListener (new WindowAdapter () {
            public void windowClosing (WindowEvent e) {
               System.exit (0) ;
            }
         }) ;
      f.pack () ;
      f.setVisible (true) ; 
   }*/

	@Override
	public void setControleur(ICCarte controleur) {
	        // TODO Auto-generated method stub
	        this.controleur=controleur;
	}

	@Override
	public ICCarte getControleur() {
		// TODO Auto-generated method stub
		return controleur;
	}

	@Override
	public Object getTransferData(DataFlavor arg0)
			throws UnsupportedFlavorException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor arg0) {
		// TODO Auto-generated method stub
		return false;
	}
	
	
}
//-------------------------------------------------------------------------------------
